// pages/personal/personal.js
import request from "../../utils/request";

let startY = 0; // 起始Y坐标
let endY = 0; // 手指移动的Y坐标
let moveDistance = 0; // 移动距离
Page({

    /**
     * 页面的初始数据
     */
    data: {
        coverTransform: 'translateY(0rpx)',
        coveTransition: '',
        userData: Object
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let userData = wx.getStorageSync('userInfo')
        if (userData) {
            this.setData({
                userData: JSON.parse(userData)
            })
        }
    },
    // 点击最近播放
    recentlyPlay() {
        if (this.data.userData) {
            wx.navigateTo({
                url: '/page/recentlyPlay/recentlyPlay'
            })
        } else {
            wx.showToast({
                title: '请您先登录',
                icon: 'none'
            })
            wx.navigateTo({
                url: '/page/login/login'
            })
        }

    },
    handlerTouchStart(event) {
        this.setData({
            coveTransition: ''
        })
        startY = event.touches[0].clientY;
    },
    handlerTouchMove(event) {
        endY = event.touches[0].clientY;
        moveDistance = endY - startY
        if (moveDistance < 0) {
            return;
        }
        if (moveDistance >= 80) {
            moveDistance = 80;
        }
        this.setData({
            coverTransform: `translateY(${moveDistance}rpx)`
        })
    },
    // 结束后回弹
    handlerTouchEnd(event) {
        this.setData({
            coverTransform: 'translateY(0rpx)',
            coveTransition: 'transform 1s linear'
        })
    },
    handlerLogin() {
        wx.navigateTo({
            url: '/page/login/login'
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})
